/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import entity.TipoUsuario;
import entity.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Rodrigo
 */
@Stateless
public class TipoUsuarioFacade extends AbstractFacade<TipoUsuario> {

    @PersistenceContext(unitName = "Epraxis-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TipoUsuarioFacade() {
        super(TipoUsuario.class);
    }

    public int removeTipoUsuarioFromUsuario(Usuario usuario) {
        String sql = "DELETE FROM USUARIO_TIPO_USUARIO WHERE USUARIO = " + usuario.getId();
        Query query = em.createNativeQuery(sql);
        int filasEliminadas = query.executeUpdate();
        return filasEliminadas;
    }

}
